home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / awksrc.zip / GAWK-D~1.14 / GAWK~9.INF (.txt) < prev    next >
GNU Info File  |  1993-10-03  |  48KB  |  920 lines

  1. This is Info file gawk.info, produced by Makeinfo-1.47 from the input
  2. file gawk.texi.
  3.    This file documents `awk', a program that you can use to select
  4. particular records in a file and perform operations upon them.
  5.    This is Edition 0.14 of `The GAWK Manual',
  6. for the 2.14 version of the GNU implementation
  7. of AWK.
  8.    Copyright (C) 1989, 1991, 1992 Free Software Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that
  14. the entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20. File: gawk.info,  Node: Numeric Functions Summary,  Next: String Functions Summary,  Prev: Special File Summary,  Up: Actions Summary
  21. Numeric Functions
  22. .................
  23.    `awk' has the following predefined arithmetic functions:
  24. `atan2(Y, X)'
  25.      returns the arctangent of Y/X in radians.
  26. `cos(EXPR)'
  27.      returns the cosine in radians.
  28. `exp(EXPR)'
  29.      the exponential function.
  30. `int(EXPR)'
  31.      truncates to integer.
  32. `log(EXPR)'
  33.      the natural logarithm function.
  34. `rand()'
  35.      returns a random number between 0 and 1.
  36. `sin(EXPR)'
  37.      returns the sine in radians.
  38. `sqrt(EXPR)'
  39.      the square root function.
  40. `srand(EXPR)'
  41.      use EXPR as a new seed for the random number generator.  If no EXPR
  42.      is provided, the time of day is used.  The return value is the
  43.      previous seed for the random number generator.
  44. File: gawk.info,  Node: String Functions Summary,  Next: Time Functions Summary,  Prev: Numeric Functions Summary,  Up: Actions Summary
  45. String Functions
  46. ................
  47.    `awk' has the following predefined string functions:
  48. `gsub(R, S, T)'
  49.      for each substring matching the regular expression R in the string
  50.      T, substitute the string S, and return the number of substitutions.
  51.      If T is not supplied, use `$0'.
  52. `index(S, T)'
  53.      returns the index of the string T in the string S, or 0 if T is
  54.      not present.
  55. `length(S)'
  56.      returns the length of the string S.  The length of `$0' is
  57.      returned if no argument is supplied.
  58. `match(S, R)'
  59.      returns the position in S where the regular expression R occurs,
  60.      or 0 if R is not present, and sets the values of `RSTART' and
  61.      `RLENGTH'.
  62. `split(S, A, R)'
  63.      splits the string S into the array A on the regular expression R,
  64.      and returns the number of fields.  If R is omitted, `FS' is used
  65.      instead.
  66. `sprintf(FMT, EXPR-LIST)'
  67.      prints EXPR-LIST according to FMT, and returns the resulting
  68.      string.
  69. `sub(R, S, T)'
  70.      this is just like `gsub', but only the first matching substring is
  71.      replaced.
  72. `substr(S, I, N)'
  73.      returns the N-character substring of S starting at I. If N is
  74.      omitted, the rest of S is used.
  75. `tolower(STR)'
  76.      returns a copy of the string STR, with all the upper-case
  77.      characters in STR translated to their corresponding lower-case
  78.      counterparts. Nonalphabetic characters are left unchanged.
  79. `toupper(STR)'
  80.      returns a copy of the string STR, with all the lower-case
  81.      characters in STR translated to their corresponding upper-case
  82.      counterparts. Nonalphabetic characters are left unchanged.
  83. `system(CMD-LINE)'
  84.      Execute the command CMD-LINE, and return the exit status.
  85. File: gawk.info,  Node: Time Functions Summary,  Next: String Constants Summary,  Prev: String Functions Summary,  Up: Actions Summary
  86. Built-in time functions
  87. .......................
  88.    The following two functions are available for getting the current
  89. time of day, and for formatting time stamps.
  90. `systime()'
  91.      returns the current time of day as the number of seconds since a
  92.      particular epoch (Midnight, January 1, 1970 UTC, on POSIX systems).
  93. `strftime(FORMAT, TIMESTAMP)'
  94.      formats TIMESTAMP according to the specification in FORMAT. The
  95.      current time of day is used if no TIMESTAMP is supplied. *Note
  96.      Functions for Dealing with Time Stamps: Time Functions, for the
  97.      details on the conversion specifiers that `strftime' accepts.
  98. File: gawk.info,  Node: String Constants Summary,  Prev: Time Functions Summary,  Up: Actions Summary
  99. String Constants
  100. ................
  101.    String constants in `awk' are sequences of characters enclosed
  102. between double quotes (`"').  Within strings, certain "escape sequences"
  103. are recognized, as in C.  These are:
  104.      A literal backslash.
  105.      The "alert" character; usually the ASCII BEL character.
  106.      Backspace.
  107.      Formfeed.
  108.      Newline.
  109.      Carriage return.
  110.      Horizontal tab.
  111.      Vertical tab.
  112. `\xHEX DIGITS'
  113.      The character represented by the string of hexadecimal digits
  114.      following the `\x'.  As in ANSI C, all following hexadecimal
  115.      digits are considered part of the escape sequence.  (This feature
  116.      should tell us something about language design by committee.) 
  117.      E.g., `"\x1B"' is a string containing the ASCII ESC (escape)
  118.      character.  (The `\x' escape sequence is not in POSIX `awk'.)
  119. `\DDD'
  120.      The character represented by the 1-, 2-, or 3-digit sequence of
  121.      octal digits.  Thus, `"\033"' is also a string containing the
  122.      ASCII ESC (escape) character.
  123.      The literal character C.
  124.    The escape sequences may also be used inside constant regular
  125. expressions (e.g., the regexp `/[ \t\f\n\r\v]/' matches whitespace
  126. characters).
  127.    *Note Constant Expressions: Constants.
  128. File: gawk.info,  Node: Functions Summary,  Next: Historical Features,  Prev: Rules Summary,  Up: Gawk Summary
  129. Functions
  130. =========
  131.    Functions in `awk' are defined as follows:
  132.      function NAME(PARAMETER LIST) { STATEMENTS }
  133.    Actual parameters supplied in the function call are used to
  134. instantiate the formal parameters declared in the function.  Arrays are
  135. passed by reference, other variables are passed by value.
  136.    If there are fewer arguments passed than there are names in
  137. PARAMETER-LIST, the extra names are given the null string as value. 
  138. Extra names have the effect of local variables.
  139.    The open-parenthesis in a function call of a user-defined function
  140. must immediately follow the function name, without any intervening
  141. white space. This is to avoid a syntactic ambiguity with the
  142. concatenation operator.
  143.    The word `func' may be used in place of `function' (but not in POSIX
  144. `awk').
  145.    Use the `return' statement to return a value from a function.
  146.    *Note User-defined Functions: User-defined, for a more complete
  147. description.
  148. File: gawk.info,  Node: Historical Features,  Prev: Functions Summary,  Up: Gawk Summary
  149. Historical Features
  150. ===================
  151.    There are two features of historical `awk' implementations that
  152. `gawk' supports.  First, it is possible to call the `length' built-in
  153. function not only with no arguments, but even without parentheses!
  154.      a = length
  155. is the same as either of
  156.      a = length()
  157.      a = length($0)
  158. This feature is marked as "deprecated" in the POSIX standard, and
  159. `gawk' will issuge a warning about its use if `-W lint' is specified on
  160. the command line.
  161.    The other feature is the use of the `continue' statement outside the
  162. body of a `while', `for', or `do' loop.  Traditional `awk'
  163. implementations have treated such usage as equivalent to the `next'
  164. statement.  `gawk' will support this usage if `-W posix' has not been
  165. specified.
  166. File: gawk.info,  Node: Sample Program,  Next: Bugs,  Prev: Gawk Summary,  Up: Top
  167. Sample Program
  168. **************
  169.    The following example is a complete `awk' program, which prints the
  170. number of occurrences of each word in its input.  It illustrates the
  171. associative nature of `awk' arrays by using strings as subscripts.  It
  172. also demonstrates the `for X in ARRAY' construction. Finally, it shows
  173. how `awk' can be used in conjunction with other utility programs to do
  174. a useful task of some complexity with a minimum of effort.  Some
  175. explanations follow the program listing.
  176.      awk '
  177.      # Print list of word frequencies
  178.      {
  179.          for (i = 1; i <= NF; i++)
  180.              freq[$i]++
  181.      }
  182.      
  183.      END {
  184.          for (word in freq)
  185.              printf "%s\t%d\n", word, freq[word]
  186.      }'
  187.    The first thing to notice about this program is that it has two
  188. rules.  The first rule, because it has an empty pattern, is executed on
  189. every line of the input.  It uses `awk''s field-accessing mechanism
  190. (*note Examining Fields: Fields.) to pick out the individual words from
  191. the line, and the built-in variable `NF' (*note Built-in Variables::.)
  192. to know how many fields are available.
  193.    For each input word, an element of the array `freq' is incremented to
  194. reflect that the word has been seen an additional time.
  195.    The second rule, because it has the pattern `END', is not executed
  196. until the input has been exhausted.  It prints out the contents of the
  197. `freq' table that has been built up inside the first action.
  198.    Note that this program has several problems that would prevent it
  199. from being useful by itself on real text files:
  200.    * Words are detected using the `awk' convention that fields are
  201.      separated by whitespace and that other characters in the input
  202.      (except newlines) don't have any special meaning to `awk'.  This
  203.      means that punctuation characters count as part of words.
  204.    * The `awk' language considers upper and lower case characters to be
  205.      distinct.  Therefore, `foo' and `Foo' are not treated by this
  206.      program as the same word.  This is undesirable since in normal
  207.      text, words are capitalized if they begin sentences, and a
  208.      frequency analyzer should not be sensitive to that.
  209.    * The output does not come out in any useful order.  You're more
  210.      likely to be interested in which words occur most frequently, or
  211.      having an alphabetized table of how frequently each word occurs.
  212.    The way to solve these problems is to use some of the more advanced
  213. features of the `awk' language.  First, we use `tolower' to remove case
  214. distinctions.  Next, we use `gsub' to remove punctuation characters. 
  215. Finally, we use the system `sort' utility to process the output of the
  216. `awk' script.  First, here is the new version of the program:
  217.      awk '
  218.      # Print list of word frequencies
  219.      {
  220.          $0 = tolower($0)    # remove case distinctions
  221.          gsub(/[^a-z0-9_ \t]/, "", $0)  # remove punctuation
  222.          for (i = 1; i <= NF; i++)
  223.              freq[$i]++
  224.      }
  225.      
  226.      END {
  227.          for (word in freq)
  228.              printf "%s\t%d\n", word, freq[word]
  229.      }'
  230.    Assuming we have saved this program in a file named `frequency.awk',
  231. and that the data is in `file1', the following pipeline
  232.      awk -f frequency.awk file1 | sort +1 -nr
  233. produces a table of the words appearing in `file1' in order of
  234. decreasing frequency.
  235.    The `awk' program suitably massages the data and produces a word
  236. frequency table, which is not ordered.
  237.    The `awk' script's output is then sorted by the `sort' command and
  238. printed on the terminal.  The options given to `sort' in this example
  239. specify to sort using the second field of each input line (skipping one
  240. field), that the sort keys should be treated as numeric quantities
  241. (otherwise `15' would come before `5'), and that the sorting should be
  242. done in descending (reverse) order.
  243.    We could have even done the `sort' from within the program, by
  244. changing the `END' action to:
  245.      END {
  246.          sort = "sort +1 -nr"
  247.          for (word in freq)
  248.              printf "%s\t%d\n", word, freq[word] | sort
  249.          close(sort)
  250.      }'
  251.    See the general operating system documentation for more information
  252. on how to use the `sort' command.
  253. File: gawk.info,  Node: Bugs,  Next: Notes,  Prev: Sample Program,  Up: Top
  254. Reporting Problems and Bugs
  255. ***************************
  256.    If you have problems with `gawk' or think that you have found a bug,
  257. please report it to the developers; we cannot promise to do anything
  258. but we might well want to fix it.
  259.    Before reporting a bug, make sure you have actually found a real bug.
  260. Carefully reread the documentation and see if it really says you can do
  261. what you're trying to do.  If it's not clear whether you should be able
  262. to do something or not, report that too; it's a bug in the
  263. documentation!
  264.    Before reporting a bug or trying to fix it yourself, try to isolate
  265. it to the smallest possible `awk' program and input data file that
  266. reproduces the problem.  Then send us the program and data file, some
  267. idea of what kind of Unix system you're using, and the exact results
  268. `gawk' gave you.  Also say what you expected to occur; this will help
  269. us decide whether the problem was really in the documentation.
  270.    Once you have a precise problem, send e-mail to (Internet)
  271. `bug-gnu-utils@prep.ai.mit.edu' or (UUCP)
  272. `mit-eddie!prep.ai.mit.edu!bug-gnu-utils'.  Please include the version
  273. number of `gawk' you are using.  You can get this information with the
  274. command `gawk -W version '{}' /dev/null'. You should send carbon copies
  275. of your mail to David Trueman at `david@cs.dal.ca', and to Arnold
  276. Robbins, who can be reached at `arnold@skeeve.atl.ga.us'.  David is
  277. most likely to fix code problems, while Arnold is most likely to fix
  278. documentation problems.
  279.    Non-bug suggestions are always welcome as well.  If you have
  280. questions about things that are unclear in the documentation or are
  281. just obscure features, ask Arnold Robbins; he will try to help you out,
  282. although he may not have the time to fix the problem.  You can send him
  283. electronic mail at the Internet address above.
  284.    If you find bugs in one of the non-Unix ports of `gawk', please send
  285. an electronic mail message to the person who maintains that port.  They
  286. are listed below, and also in the `README' file in the `gawk'
  287. distribution.  Information in the `README' file should be considered
  288. authoritative if it conflicts with this manual.
  289.    The people maintaining the non-Unix ports of `gawk' are:
  290. MS-DOS
  291.      The port to MS-DOS is maintained by Scott Deifik. His electronic
  292.      mail address is `scottd@amgen.com'.
  293.      The port to VAX VMS is maintained by Pat Rankin. His electronic
  294.      mail address is `rankin@eql.caltech.edu'.
  295. Atari ST
  296.      The port to the Atari ST is maintained by Michal Jaegermann. His
  297.      electronic mail address is `ntomczak@vm.ucs.ualberta.ca'.
  298.    If your bug is also reproducible under Unix, please send copies of
  299. your report to the general GNU bug list, as well as to Arnold Robbins
  300. and David Trueman, at the addresses listed above.
  301. File: gawk.info,  Node: Notes,  Next: Glossary,  Prev: Bugs,  Up: Top
  302. Implementation Notes
  303. ********************
  304.    This appendix contains information mainly of interest to
  305. implementors and maintainers of `gawk'.  Everything in it applies
  306. specifically to `gawk', and not to other implementations.
  307. * Menu:
  308. * Compatibility Mode::          How to disable certain `gawk' extensions.
  309. * Future Extensions::           New features we may implement soon.
  310. * Improvements::                Suggestions for improvements by volunteers.
  311. File: gawk.info,  Node: Compatibility Mode,  Next: Future Extensions,  Prev: Notes,  Up: Notes
  312. Downward Compatibility and Debugging
  313. ====================================
  314.    *Note Extensions in `gawk' not in POSIX `awk': POSIX/GNU, for a
  315. summary of the GNU extensions to the `awk' language and program. All of
  316. these features can be turned off by invoking `gawk' with the `-W
  317. compat' option, or with the `-W posix' option.
  318.    If `gawk' is compiled for debugging with `-DDEBUG', then there is
  319. one more option available on the command line:
  320. `-W debug'
  321.      Print out the parse stack information as the program is being
  322.      parsed.
  323.    This option is intended only for serious `gawk' developers, and not
  324. for the casual user.  It probably has not even been compiled into your
  325. version of `gawk', since it slows down execution.
  326. File: gawk.info,  Node: Future Extensions,  Next: Improvements,  Prev: Compatibility Mode,  Up: Notes
  327. Probable Future Extensions
  328. ==========================
  329.    This section briefly lists extensions that indicate the directions
  330. we are currently considering for `gawk'.  The file `FUTURES' in the
  331. `gawk' distributions lists these extensions, as well as several others.
  332. `RS' as a regexp
  333.      The meaning of `RS' may be generalized along the lines of `FS'.
  334. Control of subprocess environment
  335.      Changes made in `gawk' to the array `ENVIRON' may be propagated to
  336.      subprocesses run by `gawk'.
  337. Databases
  338.      It may be possible to map a GDBM/NDBM/SDBM file into an `awk'
  339.      array.
  340. Single-character fields
  341.      The null string, `""', as a field separator, will cause field
  342.      splitting and the `split' function to separate individual
  343.      characters. Thus, `split(a, "abcd", "")' would yield `a[1] == "a"',
  344.      `a[2] == "b"', and so on.
  345. More `lint' warnings
  346.      There are more things that could be checked for portability.
  347. `ARGIND' variable to indicate the position in `ARGV'
  348.      It would occasionally be useful to know which element in `ARGV' is
  349.      the current file being processed.  It is not sufficient to simply
  350.      loop through `ARGV' comparing each element to `FILENAME',
  351.      particularly if a program makes more than one pass through a single
  352.      data file.  Initially `ARGIND' would be a read-only variable. That
  353.      is, `gawk' would set it for you as each file is processed, but
  354.      would ignore any changes that your program made to it.
  355. `RECLEN' variable for fixed length records
  356.      Along with `FIELDWIDTHS', this would speed up the processing of
  357.      fixed-length records.
  358. `RT' variable to hold the record terminator
  359.      It is occasionally useful to have access to the actual string of
  360.      characters that matched the `RS' variable.  The `RT' variable
  361.      would hold these characters.
  362. A `restart' keyword
  363.      After modifying `$0', `restart' would restart the pattern matching
  364.      loop, without reading a new record from the input.
  365. A `|&' redirection
  366.      The `|&' redirection, in place of `|', would open a two-way
  367.      pipeline for communication with a sub-process (via `getline' and
  368.      `print' and `printf').
  369. `IGNORECASE' affecting all comparisons
  370.      The effects of the `IGNORECASE' variable may be generalized to all
  371.      string comparisons, and not just regular expression operations.
  372. A way to mix command line source code and library files
  373.      There may be a new option that would make it possible to easily
  374.      use library functions from a program entered on the command line.
  375. GNU-style long options
  376.      We will add GNU-style long options to `gawk' for compatibility
  377.      with other GNU programs. (For example, `--field-separator=:' would
  378.      be equivalent to `-F:'.)
  379. File: gawk.info,  Node: Improvements,  Prev: Future Extensions,  Up: Notes
  380. Suggestions for Improvements
  381. ============================
  382.    Here are some projects that would-be `gawk' hackers might like to
  383. take on.  They vary in size from a few days to a few weeks of
  384. programming, depending on which one you choose and how fast a
  385. programmer you are.  Please send any improvements you write to the
  386. maintainers at the GNU project.
  387.   1. Compilation of `awk' programs: `gawk' uses a Bison (YACC-like)
  388.      parser to convert the script given it into a syntax tree; the
  389.      syntax tree is then executed by a simple recursive evaluator. 
  390.      This method incurs a lot of overhead, since the recursive
  391.      evaluator performs many procedure calls to do even the simplest
  392.      things.
  393.      It should be possible for `gawk' to convert the script's parse tree
  394.      into a C program which the user would then compile, using the
  395.      normal C compiler and a special `gawk' library to provide all the
  396.      needed functions (regexps, fields, associative arrays, type
  397.      coercion, and so on).
  398.      An easier possibility might be for an intermediate phase of `awk'
  399.      to convert the parse tree into a linear byte code form like the
  400.      one used in GNU Emacs Lisp.  The recursive evaluator would then be
  401.      replaced by a straight line byte code interpreter that would be
  402.      intermediate in speed between running a compiled program and doing
  403.      what `gawk' does now.
  404.      This may actually happen for the 3.0 version of `gawk'.
  405.   2. An error message section has not been included in this version of
  406.      the manual.  Perhaps some nice beta testers will document some of
  407.      the messages for the future.
  408.   3. The programs in the test suite could use documenting in this
  409.      manual.
  410.   4. The programs and data files in the manual should be available in
  411.      separate files to facilitate experimentation.
  412.   5. See the `FUTURES' file for more ideas.  Contact us if you would
  413.      seriously like to tackle any of the items listed there.
  414. File: gawk.info,  Node: Glossary,  Next: Index,  Prev: Notes,  Up: Top
  415. Glossary
  416. ********
  417. Action
  418.      A series of `awk' statements attached to a rule.  If the rule's
  419.      pattern matches an input record, the `awk' language executes the
  420.      rule's action.  Actions are always enclosed in curly braces. *Note
  421.      Overview of Actions: Actions.
  422. Amazing `awk' Assembler
  423.      Henry Spencer at the University of Toronto wrote a retargetable
  424.      assembler completely as `awk' scripts.  It is thousands of lines
  425.      long, including machine descriptions for several 8-bit
  426.      microcomputers.  It is distributed with `gawk' (as part of the
  427.      test suite) and is a good example of a program that would have
  428.      been better written in another language.
  429.      The American National Standards Institute.  This organization
  430.      produces many standards, among them the standard for the C
  431.      programming language.
  432. Assignment
  433.      An `awk' expression that changes the value of some `awk' variable
  434.      or data object.  An object that you can assign to is called an
  435.      "lvalue".  *Note Assignment Expressions: Assignment Ops.
  436. `awk' Language
  437.      The language in which `awk' programs are written.
  438. `awk' Program
  439.      An `awk' program consists of a series of "patterns" and "actions",
  440.      collectively known as "rules".  For each input record given to the
  441.      program, the program's rules are all processed in turn. `awk'
  442.      programs may also contain function definitions.
  443. `awk' Script
  444.      Another name for an `awk' program.
  445. Built-in Function
  446.      The `awk' language provides built-in functions that perform various
  447.      numerical, time stamp related, and string computations.  Examples
  448.      are `sqrt' (for the square root of a number) and `substr' (for a
  449.      substring of a string).  *Note Built-in Functions: Built-in.
  450. Built-in Variable
  451.      `ARGC', `ARGV', `CONVFMT', `FIELDWIDTHS', `ENVIRON',  `FILENAME',
  452.      `FNR', `FS', `IGNORECASE', `NF', `NR', `OFMT', `OFS', `ORS',
  453.      `RLENGTH', `RSTART', `RS', and `SUBSEP', are the variables that
  454.      have special meaning to `awk'.  Changing some of them affects
  455.      `awk''s running environment.  *Note Built-in Variables::.
  456. Braces
  457.      See "Curly Braces."
  458.      The system programming language that most GNU software is written
  459.      in.  The `awk' programming language has C-like syntax, and this
  460.      manual points out similarities between `awk' and C when
  461.      appropriate.
  462.      A preprocessor for `pic' that reads descriptions of molecules and
  463.      produces `pic' input for drawing them.  It was written by Brian
  464.      Kernighan, and is available from `netlib@research.att.com'.
  465. Compound Statement
  466.      A series of `awk' statements, enclosed in curly braces.  Compound
  467.      statements may be nested. *Note Control Statements in Actions:
  468.      Statements.
  469. Concatenation
  470.      Concatenating two strings means sticking them together, one after
  471.      another, giving a new string.  For example, the string `foo'
  472.      concatenated with the string `bar' gives the string `foobar'.
  473.      *Note String Concatenation: Concatenation.
  474. Conditional Expression
  475.      An expression using the `?:' ternary operator, such as `EXPR1 ?
  476.      EXPR2 : EXPR3'.  The expression EXPR1 is evaluated; if the result
  477.      is true, the value of the whole expression is the value of EXPR2
  478.      otherwise the value is EXPR3.  In either case, only one of EXPR2
  479.      and EXPR3 is evaluated.  *Note Conditional Expressions:
  480.      Conditional Exp.
  481. Constant Regular Expression
  482.      A constant regular expression is a regular expression written
  483.      within slashes, such as `/foo/'.  This regular expression is chosen
  484.      when you write the `awk' program, and cannot be changed doing its
  485.      execution.  *Note How to Use Regular Expressions: Regexp Usage.
  486. Comparison Expression
  487.      A relation that is either true or false, such as `(a < b)'.
  488.      Comparison expressions are used in `if', `while', and `for'
  489.      statements, and in patterns to select which input records to
  490.      process. *Note Comparison Expressions: Comparison Ops.
  491. Curly Braces
  492.      The characters `{' and `}'.  Curly braces are used in `awk' for
  493.      delimiting actions, compound statements, and function bodies.
  494. Data Objects
  495.      These are numbers and strings of characters.  Numbers are
  496.      converted into strings and vice versa, as needed. *Note Conversion
  497.      of Strings and Numbers: Conversion.
  498. Dynamic Regular Expression
  499.      A dynamic regular expression is a regular expression written as an
  500.      ordinary expression.  It could be a string constant, such as
  501.      `"foo"', but it may also be an expression whose value may vary.
  502.      *Note How to Use Regular Expressions: Regexp Usage.
  503. Escape Sequences
  504.      A special sequence of characters used for describing nonprinting
  505.      characters, such as `\n' for newline, or `\033' for the ASCII ESC
  506.      (escape) character.  *Note Constant Expressions: Constants.
  507. Field
  508.      When `awk' reads an input record, it splits the record into pieces
  509.      separated by whitespace (or by a separator regexp which you can
  510.      change by setting the built-in variable `FS').  Such pieces are
  511.      called fields.  If the pieces are of fixed length, you can use the
  512.      built-in variable `FIELDWIDTHS' to describe their lengths. *Note
  513.      How Input is Split into Records: Records.
  514. Format
  515.      Format strings are used to control the appearance of output in the
  516.      `printf' statement.  Also, data conversions from numbers to strings
  517.      are controlled by the format string contained in the built-in
  518.      variable `CONVFMT'.  *Note Format-Control Letters: Control Letters.
  519. Function
  520.      A specialized group of statements often used to encapsulate general
  521.      or program-specific tasks.  `awk' has a number of built-in
  522.      functions, and also allows you to define your own. *Note Built-in
  523.      Functions: Built-in. Also, see *Note User-defined Functions:
  524.      User-defined.
  525. `gawk'
  526.      The GNU implementation of `awk'.
  527.      "GNU's not Unix".  An on-going project of the Free Software
  528.      Foundation to create a complete, freely distributable,
  529.      POSIX-compliant computing environment.
  530. Input Record
  531.      A single chunk of data read in by `awk'.  Usually, an `awk' input
  532.      record consists of one line of text. *Note How Input is Split into
  533.      Records: Records.
  534. Keyword
  535.      In the `awk' language, a keyword is a word that has special
  536.      meaning.  Keywords are reserved and may not be used as variable
  537.      names.
  538.      `awk''s keywords are: `if', `else', `while', `do...while', `for',
  539.      `for...in', `break', `continue', `delete', `next', `function',
  540.      `func', and `exit'.
  541. Lvalue
  542.      An expression that can appear on the left side of an assignment
  543.      operator.  In most languages, lvalues can be variables or array
  544.      elements.  In `awk', a field designator can also be used as an
  545.      lvalue.
  546. Number
  547.      A numeric valued data object.  The `gawk' implementation uses
  548.      double precision floating point to represent numbers.
  549. Pattern
  550.      Patterns tell `awk' which input records are interesting to which
  551.      rules.
  552.      A pattern is an arbitrary conditional expression against which
  553.      input is tested.  If the condition is satisfied, the pattern is
  554.      said to "match" the input record.  A typical pattern might compare
  555.      the input record against a regular expression.  *Note Patterns::.
  556. POSIX
  557.      The name for a series of standards being developed by the IEEE
  558.      that specify a Portable Operating System interface.  The "IX"
  559.      denotes the Unix heritage of these standards.  The main standard
  560.      of interest for `awk' users is P1003.2, the Command Language and
  561.      Utilities standard.
  562. Range (of input lines)
  563.      A sequence of consecutive lines from the input file.  A pattern
  564.      can specify ranges of input lines for `awk' to process, or it can
  565.      specify single lines.  *Note Patterns::.
  566. Recursion
  567.      When a function calls itself, either directly or indirectly. If
  568.      this isn't clear, refer to the entry for "recursion."
  569. Redirection
  570.      Redirection means performing input from other than the standard
  571.      input stream, or output to other than the standard output stream.
  572.      You can redirect the output of the `print' and `printf' statements
  573.      to a file or a system command, using the `>', `>>', and `|'
  574.      operators.  You can redirect input to the `getline' statement using
  575.      the `<' and `|' operators. *Note Redirecting Output of `print' and
  576.      `printf': Redirection.
  577. Regular Expression
  578.      See "regexp."
  579. Regexp
  580.      Short for "regular expression".  A regexp is a pattern that
  581.      denotes a set of strings, possibly an infinite set.  For example,
  582.      the regexp `R.*xp' matches any string starting with the letter `R'
  583.      and ending with the letters `xp'.  In `awk', regexps are used in
  584.      patterns and in conditional expressions.  Regexps may contain
  585.      escape sequences.  *Note Regular Expressions as Patterns: Regexp.
  586.      A segment of an `awk' program, that specifies how to process single
  587.      input records.  A rule consists of a "pattern" and an "action".
  588.      `awk' reads an input record; then, for each rule, if the input
  589.      record satisfies the rule's pattern, `awk' executes the rule's
  590.      action. Otherwise, the rule does nothing for that input record.
  591. Side Effect
  592.      A side effect occurs when an expression has an effect aside from
  593.      merely producing a value.  Assignment expressions, increment
  594.      expressions and function calls have side effects.  *Note
  595.      Assignment Expressions: Assignment Ops.
  596. Special File
  597.      A file name interpreted internally by `gawk', instead of being
  598.      handed directly to the underlying operating system.  For example,
  599.      `/dev/stdin'. *Note Standard I/O Streams: Special Files.
  600. Stream Editor
  601.      A program that reads records from an input stream and processes
  602.      them one or more at a time.  This is in contrast with batch
  603.      programs, which may expect to read their input files in entirety
  604.      before starting to do anything, and with interactive programs,
  605.      which require input from the user.
  606. String
  607.      A datum consisting of a sequence of characters, such as `I am a
  608.      string'.  Constant strings are written with double-quotes in the
  609.      `awk' language, and may contain escape sequences. *Note Constant
  610.      Expressions: Constants.
  611. Whitespace
  612.      A sequence of blank or tab characters occurring inside an input
  613.      record or a string.
  614. File: gawk.info,  Node: Index,  Prev: Glossary,  Up: Top
  615. Index
  616. *****
  617. * Menu:
  618. * $ (field operator):                   Fields.
  619. * AWKPATH environment variable:         AWKPATH Variable.
  620. * BEGIN special pattern:                BEGIN/END.
  621. * END special pattern:                  BEGIN/END.
  622. * awk language:                         This Manual.
  623. * awk program:                          This Manual.
  624. * break statement:                      Break Statement.
  625. * continue statement:                   Continue Statement.
  626. * delete statement:                     Delete.
  627. * exit statement:                       Exit Statement.
  628. * for (x in ...):                       Scanning an Array.
  629. * for statement:                        For Statement.
  630. * if statement:                         If Statement.
  631. * next file statement:                  Next File Statement.
  632. * next statement:                       Next Statement.
  633. * printf statement, syntax of:          Basic Printf.
  634. * printf, format-control characters:    Control Letters.
  635. * printf, modifiers:                    Format Modifiers.
  636. * print statement:                      Print.
  637. * return statement:                     Return Statement.
  638. * while statement:                      While Statement.
  639. * /dev/fd/:                             Special Files.
  640. * /dev/stderr:                          Special Files.
  641. * /dev/stdin:                           Special Files.
  642. * /dev/stdout:                          Special Files.
  643. * BBS-list file:                        Sample Data Files.
  644. * inventory-shipped file:               Sample Data Files.
  645. * #!:                                   Executable Scripts.
  646. * #:                                    Comments.
  647. * -F option:                            Field Separators.
  648. * -W option:                            Options.
  649. * -f option:                            Long.
  650. * -v option:                            Options.
  651. * print $0:                             Very Simple.
  652. * ARGV:                                 Other Arguments.
  653. * CONVFMT:                              Comparison Ops.
  654. * CONVFMT:                              Numeric Array Subscripts.
  655. * CONVFMT:                              Conversion.
  656. * ENVIRON:                              Auto-set.
  657. * FILENAME:                             Reading Files.
  658. * FNR:                                  Records.
  659. * FS:                                   Field Separators.
  660. * NF:                                   Fields.
  661. * NR:                                   Records.
  662. * OFMT:                                 OFMT.
  663. * OFMT:                                 Conversion.
  664. * OFS:                                  Output Separators.
  665. * ORS:                                  Output Separators.
  666. * RLENGTH:                              String Functions.
  667. * RS:                                   Records.
  668. * RSTART:                               String Functions.
  669. * SUBSEP:                               Multi-dimensional.
  670. * accessing fields:                     Fields.
  671. * acronym:                              History.
  672. * action, curly braces:                 Actions.
  673. * action, default:                      Very Simple.
  674. * action, definition of:                Actions.
  675. * action, separating statements:        Actions.
  676. * addition:                             Arithmetic Ops.
  677. * and operator:                         Boolean Ops.
  678. * anonymous ftp:                        Extracting.
  679. * anonymous uucp:                       Extracting.
  680. * applications of awk:                  When.
  681. * arguments in function call:           Function Calls.
  682. * arguments, command line:              Command Line.
  683. * arithmetic operators:                 Arithmetic Ops.
  684. * array assignment:                     Assigning Elements.
  685. * array reference:                      Reference to Elements.
  686. * arrays:                               Array Intro.
  687. * arrays, definition of:                Array Intro.
  688. * arrays, deleting an element:          Delete.
  689. * arrays, multi-dimensional subscripts: Multi-dimensional.
  690. * arrays, presence of elements:         Reference to Elements.
  691. * arrays, special for statement:        Scanning an Array.
  692. * assignment operators:                 Assignment Ops.
  693. * assignment to fields:                 Changing Fields.
  694. * associative arrays:                   Array Intro.
  695. * backslash continuation:               Statements/Lines.
  696. * basic function of gawk:               Getting Started.
  697. * body of a loop:                       While Statement.
  698. * boolean expressions:                  Boolean Ops.
  699. * boolean operators:                    Boolean Ops.
  700. * boolean patterns:                     Boolean Patterns.
  701. * buffering output:                     I/O Functions.
  702. * buffers, flushing:                    I/O Functions.
  703. * built-in functions:                   Built-in.
  704. * built-in variables:                   Built-in Variables.
  705. * built-in variables, user modifiable:  User-modified.
  706. * call by reference:                    Function Caveats.
  707. * call by value:                        Function Caveats.
  708. * calling a function:                   Function Calls.
  709. * case sensitivity:                     Read Terminal.
  710. * changing contents of a field:         Changing Fields.
  711. * close:                                Close Input.
  712. * close:                                Close Output.
  713. * closing input files and pipes:        Close Input.
  714. * closing output files and pipes:       Close Output.
  715. * command line:                         Command Line.
  716. * command line formats:                 Running gawk.
  717. * command line, setting FS on:          Field Separators.
  718. * comments:                             Comments.
  719. * comparison expressions:               Comparison Ops.
  720. * comparison expressions as patterns:   Comparison Patterns.
  721. * computed regular expressions:         Regexp Usage.
  722. * concatenation:                        Concatenation.
  723. * conditional expression:               Conditional Exp.
  724. * constants, types of:                  Constants.
  725. * continuation of lines:                Statements/Lines.
  726. * control statement:                    Statements.
  727. * conversion of strings and numbers:    Conversion.
  728. * conversion of strings and numbers:    Values.
  729. * conversions, during subscripting:     Numeric Array Subscripts.
  730. * curly braces:                         Actions.
  731. * default action:                       Very Simple.
  732. * default pattern:                      Very Simple.
  733. * defining functions:                   Definition Syntax.
  734. * deleting elements of arrays:          Delete.
  735. * deprecated features:                  Obsolete.
  736. * deprecated options:                   Obsolete.
  737. * directory search:                     AWKPATH Variable.
  738. * division:                             Arithmetic Ops.
  739. * documenting awk programs:             Comments.
  740. * dynamic regular expressions:          Regexp Usage.
  741. * element assignment:                   Assigning Elements.
  742. * element of array:                     Reference to Elements.
  743. * empty pattern:                        Empty.
  744. * escape sequence notation:             Constants.
  745. * examining fields:                     Fields.
  746. * executable scripts:                   Executable Scripts.
  747. * explicit input:                       Getline.
  748. * exponentiation:                       Arithmetic Ops.
  749. * expression:                           Expressions.
  750. * expression, conditional:              Conditional Exp.
  751. * expressions, assignment:              Assignment Ops.
  752. * expressions, boolean:                 Boolean Ops.
  753. * expressions, comparison:              Comparison Ops.
  754. * field separator, FS:                  Field Separators.
  755. * field separator, choice of:           Field Separators.
  756. * field separator: on command line:     Field Separators.
  757. * field, changing contents of:          Changing Fields.
  758. * fields:                               Fields.
  759. * fields, separating:                   Field Separators.
  760. * file descriptors:                     Special Files.
  761. * file, awk program:                    Long.
  762. * flushing buffers:                     I/O Functions.
  763. * format specifier:                     Control Letters.
  764. * format string:                        Basic Printf.
  765. * formatted output:                     Printf.
  766. * ftp, anonymous:                       Extracting.
  767. * function call:                        Function Calls.
  768. * function definition:                  Definition Syntax.
  769. * functions, user-defined:              User-defined.
  770. * getline:                              Getline.
  771. * getting gawk:                         Extracting.
  772. * gsub:                                 String Functions.
  773. * history of awk:                       History.
  774. * how awk works:                        Two Rules.
  775. * increment operators:                  Increment Ops.
  776. * input:                                Reading Files.
  777. * input file, sample:                   Sample Data Files.
  778. * input redirection:                    Getline.
  779. * input, getline command:               Getline.
  780. * input, explicit:                      Getline.
  781. * input, multiple line records:         Multiple Line.
  782. * input, standard:                      Read Terminal.
  783. * installation, atari:                  Atari Installation.
  784. * installation, ms-dos:                 MS-DOS Installation.
  785. * installation, unix:                   Quick Installation.
  786. * installation, vms:                    VMS Installation.
  787. * interaction, awk and other programs:  I/O Functions.
  788. * invocation of gawk:                   Command Line.
  789. * language, awk:                        This Manual.
  790. * length:                               String Functions.
  791. * logical operations:                   Boolean Ops.
  792. * loop:                                 While Statement.
  793. * loops, exiting:                       Break Statement.
  794. * lvalue:                               Assignment Ops.
  795. * manual, using this:                   This Manual.
  796. * match:                                String Functions.
  797. * match:                                String Functions.
  798. * metacharacters:                       Regexp Operators.
  799. * modifiers (in format specifiers):     Format Modifiers.
  800. * multi-dimensional subscripts:         Multi-dimensional.
  801. * multiple line records:                Multiple Line.
  802. * multiple passes over data:            Other Arguments.
  803. * multiple statements on one line:      Statements/Lines.
  804. * multiplication:                       Arithmetic Ops.
  805. * not operator:                         Boolean Ops.
  806. * number of fields, NF:                 Fields.
  807. * number of records, NR or FNR:         Records.
  808. * numbers, used as subscripts:          Numeric Array Subscripts.
  809. * numeric constant:                     Constants.
  810. * numeric value:                        Constants.
  811. * obsolete features:                    Obsolete.
  812. * obsolete options:                     Obsolete.
  813. * one-liners:                           One-liners.
  814. * operator precedence:                  Precedence.
  815. * operators, $:                         Fields.
  816. * operators, arithmetic:                Arithmetic Ops.
  817. * operators, assignment:                Assignment Ops.
  818. * operators, boolean:                   Boolean Ops.
  819. * operators, increment:                 Increment Ops.
  820. * operators, regexp matching:           Regexp Usage.
  821. * operators, relational:                Comparison Ops.
  822. * operators, relational:                Comparison Patterns.
  823. * operators, string:                    Concatenation.
  824. * operators, string-matching:           Regexp Usage.
  825. * options, command line:                Command Line.
  826. * or operator:                          Boolean Ops.
  827. * output:                               Printing.
  828. * output field separator, OFS:          Output Separators.
  829. * output record separator, ORS:         Output Separators.
  830. * output redirection:                   Redirection.
  831. * output, buffering:                    I/O Functions.
  832. * output, formatted:                    Printf.
  833. * output, piping:                       File/Pipe Redirection.
  834. * passes, multiple:                     Other Arguments.
  835. * path, search:                         AWKPATH Variable.
  836. * pattern, case sensitive:              Read Terminal.
  837. * pattern, comparison expressions:      Comparison Patterns.
  838. * pattern, default:                     Very Simple.
  839. * pattern, definition of:               Patterns.
  840. * pattern, empty:                       Empty.
  841. * pattern, regular expressions:         Regexp.
  842. * patterns, BEGIN:                      BEGIN/END.
  843. * patterns, END:                        BEGIN/END.
  844. * patterns, boolean:                    Boolean Patterns.
  845. * patterns, range:                      Ranges.
  846. * patterns, types of:                   Kinds of Patterns.
  847. * pipes for output:                     File/Pipe Redirection.
  848. * precedence:                           Precedence.
  849. * printing:                             Printing.
  850. * program file:                         Long.
  851. * program, awk:                         This Manual.
  852. * program, definition of:               Getting Started.
  853. * program, self contained:              Executable Scripts.
  854. * programs, documenting:                Comments.
  855. * quotient:                             Arithmetic Ops.
  856. * range pattern:                        Ranges.
  857. * reading files:                        Reading Files.
  858. * reading files, getline command:       Getline.
  859. * reading files, multiple line records: Multiple Line.
  860. * record separator:                     Records.
  861. * records, multiple line:               Multiple Line.
  862. * redirection of input:                 Getline.
  863. * redirection of output:                Redirection.
  864. * reference to array:                   Reference to Elements.
  865. * regexp:                               Regexp.
  866. * regexp as expression:                 Comparison Ops.
  867. * regexp operators:                     Comparison Ops.
  868. * regexp search operators:              Regexp Usage.
  869. * regular expression matching operators: Regexp Usage.
  870. * regular expression metacharacters:    Regexp Operators.
  871. * regular expressions as field separators: Field Separators.
  872. * regular expressions as patterns:      Regexp.
  873. * regular expressions, computed:        Regexp Usage.
  874. * relational operators:                 Comparison Ops.
  875. * relational operators:                 Comparison Patterns.
  876. * remainder:                            Arithmetic Ops.
  877. * removing elements of arrays:          Delete.
  878. * rule, definition of:                  Getting Started.
  879. * running awk programs:                 Running gawk.
  880. * running long programs:                Long.
  881. * sample input file:                    Sample Data Files.
  882. * scanning an array:                    Scanning an Array.
  883. * script, definition of:                Getting Started.
  884. * scripts, executable:                  Executable Scripts.
  885. * scripts, shell:                       Executable Scripts.
  886. * search path:                          AWKPATH Variable.
  887. * self contained programs:              Executable Scripts.
  888. * shell scripts:                        Executable Scripts.
  889. * side effect:                          Assignment Ops.
  890. * single quotes, why needed:            One-shot.
  891. * split:                                String Functions.
  892. * sprintf:                              String Functions.
  893. * standard error output:                Special Files.
  894. * standard input:                       Read Terminal.
  895. * standard input:                       Reading Files.
  896. * standard input:                       Special Files.
  897. * standard output:                      Special Files.
  898. * strftime:                             Time Functions.
  899. * string constants:                     Constants.
  900. * string operators:                     Concatenation.
  901. * string-matching operators:            Regexp Usage.
  902. * sub:                                  String Functions.
  903. * subscripts in arrays:                 Multi-dimensional.
  904. * substr:                               String Functions.
  905. * subtraction:                          Arithmetic Ops.
  906. * system:                               I/O Functions.
  907. * systime:                              Time Functions.
  908. * time of day:                          Time Functions.
  909. * time stamps:                          Time Functions.
  910. * tolower:                              String Functions.
  911. * toupper:                              String Functions.
  912. * use of comments:                      Comments.
  913. * user-defined functions:               User-defined.
  914. * user-defined variables:               Variables.
  915. * uses of awk:                          Preface.
  916. * using this manual:                    This Manual.
  917. * uucp, anonymous:                      Extracting.
  918. * variables, user-defined:              Variables.
  919. * when to use awk:                      When.
  920.